import type {Router} from "vue-router";
import {stores} from "@/base/stores";
import {logout} from "@/base/ts/service/AuthService.ts";

export default function (router: Router) {
  router.beforeEach((to, from, next) => {
    //不是outside的页面直接放行
    if (to.path?.startsWith('/outside/')) {
      next();
      return;
    }

    //未登录或以login结尾,跳转登录页面
    if (!stores().user.userInfo?.token || to.path.endsWith('/login')) {
      logout();
      return;
    }
    next();
  })
}